/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Formas;

import datos.*;
import Reporteria.*;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;

/**
 *
 * @author lupiss
 */
public class InterPerfil extends javax.swing.JInternalFrame {
    private BDAdmin objCon=new BDAdmin();
    private FileInputStream fis;
    private int longitudBytes;
    private ControllerCliente cc;
    public tratadatos objDatos=new tratadatos();
    private Cifrador c=new Cifrador(); 
    private ReportePerfil objRepo=new ReportePerfil();
    private BDAdmin concli = new BDAdmin();
    /**
     * Creates new form InterPerfil
     */
    public InterPerfil() {
        initComponents();
        cc = new ControllerCliente();
        lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
        //jT_buscanomina.setText(ServerBridge.get);
        jF_fecha.setText(ServerBridge.getfechasistemacompleta());
        cargaDatosusuario();
        //cargaDatosPerfi();
        //cargaDatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lb_foto = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jT_nombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jC_posicion = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jT_nunomina = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jC_dpto = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jC_niveleducativo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jF_fecha = new javax.swing.JFormattedTextField();
        jLabel15 = new javax.swing.JLabel();
        jC_tipo = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jT_uniclave = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jB_edita = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jP_contra = new javax.swing.JPasswordField();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTA_RYR = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTA_NYP = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTA_PYE = new javax.swing.JTextArea();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTA_principio = new javax.swing.JTextArea();
        jLabel14 = new javax.swing.JLabel();
        jC_cursos = new javax.swing.JComboBox();
        jCh_activa = new javax.swing.JCheckBox();
        jT_buscanomina = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Informacion General del Trabajador");

        lb_foto.setAutoscrolls(true);
        lb_foto.setMaximumSize(new java.awt.Dimension(2, 2));
        lb_foto.setMinimumSize(new java.awt.Dimension(2, 2));
        lb_foto.setPreferredSize(new java.awt.Dimension(2, 2));
        lb_foto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lb_fotoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_foto, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_foto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("DATOS GENERALES");

        jLabel3.setText("Nombre:");

        jT_nombre.setEditable(false);

        jLabel4.setText("Posicion:");

        jC_posicion.setEditable(true);
        jC_posicion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Técnico Mecánico", "Op. de Refrigeración", "Técnico de Refrigeración", "Op. de PTAR.", "Jefatura", "Técnico Instrumentista" }));
        jC_posicion.setEnabled(false);
        jC_posicion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jC_posicionActionPerformed(evt);
            }
        });

        jLabel11.setText("No. Nomina:");

        jT_nunomina.setEditable(false);
        jT_nunomina.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jT_nunomina.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel5.setText("Departamento:");

        jC_dpto.setEditable(true);
        jC_dpto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mantenimiento", "Sala de Maq. de Refrigeración", "PTAR", "Ingenieria de Planta" }));
        jC_dpto.setEnabled(false);

        jLabel6.setText("Nivel Educativo:");

        jC_niveleducativo.setEditable(true);
        jC_niveleducativo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Técnico", "TSU", "Ingeniero" }));
        jC_niveleducativo.setEnabled(false);

        jLabel7.setText("Fecha de Ingreso:");

        jF_fecha.setEditable(false);
        try {
            jF_fecha.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jF_fecha.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel15.setText("Tipo:");

        jC_tipo.setEditable(true);
        jC_tipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Usuario", "Administrador" }));
        jC_tipo.setEnabled(false);

        jLabel13.setText("UNICLAVE:");

        jT_uniclave.setEditable(false);
        jT_uniclave.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jButton1.setText("Imprimir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jB_edita.setText("Editar");
        jB_edita.setEnabled(false);
        jB_edita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_editaActionPerformed(evt);
            }
        });

        jLabel17.setText("Contraseña:");

        jP_contra.setEditable(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(327, 327, 327)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jT_uniclave)
                            .addComponent(jC_tipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jB_edita)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jP_contra, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(jT_nunomina, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel4)
                        .addComponent(jLabel5)
                        .addComponent(jLabel6)
                        .addComponent(jLabel7)
                        .addComponent(jLabel3))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jT_nombre)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jC_posicion, 0, 175, Short.MAX_VALUE)
                                .addComponent(jC_dpto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jC_niveleducativo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jF_fecha))
                            .addGap(0, 0, Short.MAX_VALUE)))
                    .addContainerGap()))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jT_nunomina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jP_contra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jT_uniclave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jC_tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jB_edita))
                .addGap(22, 22, 22))
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(46, 46, 46)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jT_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jC_posicion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jC_dpto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jC_niveleducativo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addGap(24, 24, 24)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jF_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(21, Short.MAX_VALUE)))
        );

        jLabel8.setText("Roles y Responsabilidades:");

        jTA_RYR.setEditable(false);
        jTA_RYR.setColumns(20);
        jTA_RYR.setRows(5);
        jScrollPane1.setViewportView(jTA_RYR);

        jLabel9.setText("Normas:");

        jTA_NYP.setEditable(false);
        jTA_NYP.setColumns(20);
        jTA_NYP.setRows(5);
        jScrollPane2.setViewportView(jTA_NYP);

        jLabel10.setText("Propiedades del Equipo:");

        jTA_PYE.setEditable(false);
        jTA_PYE.setColumns(20);
        jTA_PYE.setRows(5);
        jScrollPane3.setViewportView(jTA_PYE);

        jLabel12.setText("Principios:");

        jTA_principio.setEditable(false);
        jTA_principio.setColumns(20);
        jTA_principio.setRows(5);
        jScrollPane4.setViewportView(jTA_principio);

        jLabel14.setText("Cursos y Certificaciones:");

        jCh_activa.setText("Activar para Editar");
        jCh_activa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCh_activaActionPerformed(evt);
            }
        });

        jT_buscanomina.setEditable(false);
        jT_buscanomina.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jT_buscanominaKeyPressed(evt);
            }
        });

        jLabel16.setText("No. Nomina:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane3)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jC_cursos, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jT_buscanomina, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCh_activa, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel12)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(jC_cursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel16))
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCh_activa)
                        .addComponent(jT_buscanomina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jButton2.setText("Salir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jButton2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    public void cargaDatosusuario(){
        String query = "select nombre,departamento,posicion,tipo_usuario,cveusuario "
                + "from usuarios where cveusuario = '" +ServerBridge.getidentificadorUsuario() + "'";
        String res = concli.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        //JOptionPane.showMessageDialog(this,query);
        String[] tipo = res.split("\\,");
        //jL_usuario.setText(tipo[0]);
        //jL_tipousuario.setText(tipo[3]);
        //jL_posicion.setText(tipo[2]);
        //_departamento.setText(tipo[1]);
        jT_buscanomina.setText(tipo[4]);
        
        
    
    }
    
    
    public void cargaDatos(){
    String querfc = "select cveusuario from usuarios where cveusuario='" + ServerBridge.getidentificadorUsuario() + "' and status='A'";
            String res1 = objCon.consultar(querfc, ServerBridge.getusuBD(), ServerBridge.getpasBD());
            String datos[] = res1.split(",");
           
                
                    //System.out.println("CONSULTA DATOS");
                    String queryDat = "select * from usuarios where cveusuario='" + ServerBridge.getidentificadorUsuario() + "'";
                    String resdat = objCon.consultarB(queryDat, ServerBridge.getusuBD(), ServerBridge.getpasBD());
                    String datosdat[] = resdat.split("\\¬");
                    System.out.println(queryDat);
                    jT_nombre.setText(datosdat[2]);
                    jT_nunomina.setText(datosdat[1]);
                    //System.out.println(c.desencriptar(datosdat[3]));
                    jT_uniclave.setText(datosdat[10]);
                    jC_posicion.setSelectedItem(datosdat[8]);
                    jC_dpto.setSelectedItem(datosdat[4]);
                    jC_niveleducativo.setSelectedItem(datosdat[9]);
                    jTA_NYP.setText(datosdat[12]);
                    jTA_PYE.setText(datosdat[13]);
                    jTA_RYR.setText(datosdat[11]);
                    jC_tipo.setSelectedItem(datosdat[14]);
                    jF_fecha.setText(cargafecha(datosdat[7]));
                    jTA_principio.setText(datosdat[15]);
                    CustomImageIcon foto = ConexionBase.getFoto(datosdat[10]);
                    ImageIcon fot=ConexionBase.getFoto(datosdat[10]);
                    //System.out.println(foto);
                    if(fot!=null)
                    {   
                        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lb_foto.getWidth(), lb_foto.getHeight(), Image.SCALE_DEFAULT));
                        lb_foto.setIcon(icono);
                    }else{
                        
                     lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
                    }
                    lb_foto.updateUI();
                    
                
            
    }
    
    public String cargafecha(String dato){
    String datos[] = dato.split("\\s");
    String datos1[] = datos[0].split("\\-");
    return datos1[2]+"/"+datos1[1]+"/"+datos1[0];
    }
    
    private void jC_posicionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jC_posicionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jC_posicionActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        objRepo.doReport(jT_nunomina.getText());// TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int i = JOptionPane.showConfirmDialog(this, "Desea salir de perfil", "Confirmacion", JOptionPane.YES_NO_OPTION);
        if (i == 0) {
            this.dispose();
        }// TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void lb_fotoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_fotoMouseClicked
         JFileChooser se=new JFileChooser();
        se.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int estado=se.showOpenDialog(null);
        if(estado==JFileChooser.APPROVE_OPTION){
            try{
            fis=new FileInputStream(se.getSelectedFile());
                //System.out.println(fis);
            this.longitudBytes=(int)se.getSelectedFile().length();
            Image icon=ImageIO.read(se.getSelectedFile()).getScaledInstance(lb_foto.getWidth(),lb_foto.getHeight(),Image.SCALE_DEFAULT);
            lb_foto.setIcon(new ImageIcon(icon));
            lb_foto.updateUI();
            }catch(FileNotFoundException ex){ex.printStackTrace();}
            catch(IOException ex){ex.printStackTrace();}
        }// TODO add your handling code here:
    }//GEN-LAST:event_lb_fotoMouseClicked
    
    public void cargaDatosPerfi(){
    String querfc = "select cveusuario from usuarios where cveusuario='" + jT_buscanomina.getText() + "' and status='A'";
            String res1 = objCon.consultar(querfc, ServerBridge.getusuBD(), ServerBridge.getpasBD());
            String datos[] = res1.split(",");
            if(datos[0].equals(jT_buscanomina.getText())){
                if(consultarPsw(jT_buscanomina.getText())){
                    //System.out.println("CONSULTA DATOS");
                    String queryDat = "select * from usuarios where cveusuario='" + jT_buscanomina.getText() + "'";
                    String resdat = objCon.consultarB(queryDat, ServerBridge.getusuBD(), ServerBridge.getpasBD());
                    String datosdat[] = resdat.split("\\¬");
                    System.out.println(queryDat);
                    jT_nombre.setText(datosdat[2]);
                    jT_nunomina.setText(datosdat[1]);
                    jP_contra.setText(c.desencriptar(datosdat[3]));
                    System.out.println(c.desencriptar(datosdat[3]));
                    jT_uniclave.setText(datosdat[10]);
                    jC_posicion.setSelectedItem(datosdat[8]);
                    jC_dpto.setSelectedItem(datosdat[4]);
                    jC_niveleducativo.setSelectedItem(datosdat[9]);
                    jTA_NYP.setText(datosdat[12]);
                    jTA_PYE.setText(datosdat[13]);
                    jTA_RYR.setText(datosdat[11]);
                    jC_tipo.setSelectedItem(datosdat[14]);
                    jF_fecha.setText(cargafecha(datosdat[7]));
                    jTA_principio.setText(datosdat[15]);
                    CustomImageIcon foto = ConexionBase.getFoto(datosdat[10]);
                    ImageIcon fot=ConexionBase.getFoto(datosdat[10]);
                    //System.out.println(foto);
                    if(fot!=null)
                    {   
                        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lb_foto.getWidth(), lb_foto.getHeight(), Image.SCALE_DEFAULT));
                    
                        lb_foto.setIcon(icono);
                    }else{
                        
                     lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
                    }
                    lb_foto.updateUI();
                    
                    
                }else{
                    JOptionPane.showMessageDialog(this,"La contraseña es incorrecta");
                }
            }else{
            JOptionPane.showMessageDialog(this,"No existe el numero de nomina introducido o ya esta dado de baja");
            }
    
    }
    
    
    
    private void jT_buscanominaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jT_buscanominaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.setKeyCode(0);
            if(jT_buscanomina.getText().equals("")){
             JOptionPane.showMessageDialog(this,"Debe ingresar datos");
            }else{
            String querfc = "select cveusuario from usuarios where cveusuario='" + jT_buscanomina.getText() + "' and status='A'";
            String res1 = objCon.consultar(querfc, ServerBridge.getusuBD(), ServerBridge.getpasBD());
            String datos[] = res1.split(",");
            if(datos[0].equals(jT_buscanomina.getText())){
                if(consultarPsw(jT_buscanomina.getText())){
                    //System.out.println("CONSULTA DATOS");
                    String queryDat = "select * from usuarios where cveusuario='" + jT_buscanomina.getText() + "'";
                    String resdat = objCon.consultarB(queryDat, ServerBridge.getusuBD(), ServerBridge.getpasBD());
                    String datosdat[] = resdat.split("\\¬");
                    System.out.println(queryDat);
                    jT_nombre.setText(datosdat[2]);
                    jT_nunomina.setText(datosdat[1]);
                    jP_contra.setText(c.desencriptar(datosdat[3]));
                    System.out.println(c.desencriptar(datosdat[3]));
                    jT_uniclave.setText(datosdat[10]);
                    jC_posicion.setSelectedItem(datosdat[8]);
                    jC_dpto.setSelectedItem(datosdat[4]);
                    jC_niveleducativo.setSelectedItem(datosdat[9]);
                    jTA_NYP.setText(datosdat[12]);
                    jTA_PYE.setText(datosdat[13]);
                    jTA_RYR.setText(datosdat[11]);
                    jC_tipo.setSelectedItem(datosdat[14]);
                    jF_fecha.setText(cargafecha(datosdat[7]));
                    jTA_principio.setText(datosdat[15]);
                    CustomImageIcon foto = ConexionBase.getFoto(datosdat[10]);
                    ImageIcon fot=ConexionBase.getFoto(datosdat[10]);
                    //System.out.println(foto);
                    if(fot!=null)
                    {   
                        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lb_foto.getWidth(), lb_foto.getHeight(), Image.SCALE_DEFAULT));
                    
                        lb_foto.setIcon(icono);
                    }else{
                        
                     lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
                    }
                    lb_foto.updateUI();
                    
                    
                }else{
                    JOptionPane.showMessageDialog(this,"La contraseña es incorrecta");
                }
            }else{
            JOptionPane.showMessageDialog(this,"No existe el numero de nomina introducido o ya esta dado de baja");
            }
        }}// TODO add your handling code here:
    }//GEN-LAST:event_jT_buscanominaKeyPressed

    private void jCh_activaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCh_activaActionPerformed
        if(jCh_activa.isSelected()){
        activaCampos();
        }else{
        desactivaCampos();
        }// TODO add your handling code here:
    }//GEN-LAST:event_jCh_activaActionPerformed

    private void jB_editaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_editaActionPerformed
        updatePerfil();// TODO add your handling code here:
    }//GEN-LAST:event_jB_editaActionPerformed
    
    public String devuelvePass(String dato){
    //String text=StringMD.getStringMessageDigest(dato,"SHA-256");
        String text=c.encriptar(dato);
    return text;
    }
    
    public String fechaInsert(String dato){
    String datos[] = dato.split("\\/");
    return (datos[2]+"-"+datos[1]+"-"+datos[0]+" 12:00:000");
    }
    
    public void updatePerfil(){
        String querUp="update usuarios set "
                + "nombre='"+jT_nombre.getText()+"',"
                + "password='"+devuelvePass(jP_contra.getText())+"',"
                + "departamento='"+jC_dpto.getSelectedItem()+"',"
                + "observaciones='SIN OBSERVACIONES',"
                + "fecha_alta='"+fechaInsert(jF_fecha.getText())+"',"
                + "posicion='"+jC_posicion.getSelectedItem()+"',"
                + "niveledu='"+jC_niveleducativo.getSelectedItem()+"',"
                + "RYR='"+jTA_RYR.getText()+"',"
                + "NYP='"+jTA_NYP.getText()+"',"
                + "PDE='"+jTA_PYE.getText()+"',"
                + "tipo_usuario='"+jC_tipo.getSelectedItem()+"',"
                + "prin='"+jTA_principio.getText()+"' where uniclave='"+jT_uniclave.getText()+"'";
        //System.out.println(querUp);
        String res = objCon.modificar(querUp, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        if (res.equals("Exito!")) {
            JOptionPane.showMessageDialog(this, "Se actualizo correcatamente el perfil");
            LimpiaDatos();
            lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
        } else {
            JOptionPane.showMessageDialog(this, "Ocurrio un error al dar de baja la maquina");
        }
    }
    
    public void LimpiaDatos(){
    jT_nombre.setText("");
    jT_nunomina.setText("");
    jP_contra.setText("");
    jT_uniclave.setText(objDatos.getCadenaAlfanumAleatoria(8));
    jC_posicion.setSelectedIndex(0);
    jC_dpto.setSelectedIndex(0);
    jC_niveleducativo.setSelectedIndex(0);
    jC_tipo.setSelectedIndex(0);
    jTA_NYP.setText("");
    jTA_PYE.setText("");
    jTA_RYR.setText("");
    lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultlarge.gif")));
    jTA_principio.setText("");
    jF_fecha.setText(ServerBridge.getfechasistemacompleta());
    }
    
    public void activaCampos(){
    cargaDatosPerfi();
        jT_nombre.setEditable(true);
    jC_posicion.setEnabled(true);
    jT_nunomina.setEditable(true);
    jC_dpto.setEnabled(true);
    jP_contra.setEditable(true);
    jC_niveleducativo.setEnabled(true);
    jC_tipo.setEnabled(true);
    jF_fecha.setEditable(true);
    jTA_RYR.setEditable(true);
    jTA_NYP.setEditable(true);
    jTA_principio.setEditable(true);
    jTA_PYE.setEditable(true);
    jB_edita.setEnabled(true);
    
    }
    
    public void desactivaCampos(){
    jT_nombre.setEditable(false);
    jC_posicion.setEnabled(false);
    jT_nunomina.setEditable(false);
    jC_dpto.setEnabled(false);
    jP_contra.setEditable(false);
    jC_niveleducativo.setEnabled(false);
    jC_tipo.setEnabled(false);
    jF_fecha.setEditable(false);
    jTA_RYR.setEditable(false);
    jTA_NYP.setEditable(false);
    jTA_principio.setEditable(false);
    jTA_PYE.setEditable(false);
    jB_edita.setEnabled(false);
    }
    
    public boolean consultarPsw(String dato) {
        String query = "select password from usuarios where cveusuario = '" + dato + "'";
        String res = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String datos[] = res.split(",");
        String password=c.desencriptar(datos[0]);
        //System.out.println(datos[0]);
        //System.out.println(password);
        //String password = res.substring(0, res.length() - 1);
        //String passText = StringMD.getStringMessageDigest(jPasswordFieldJoin.getText(), "SHA-256");
        //JOptionPane.showMessageDialog(this,passText);        
        //System.out.println(password);
        //System.out.println(passText);
        if (password.equals(selectPassword())) {
            return true;
        } else {
            return false;
        }
    }

    private String selectPassword() {
        JPasswordField pwd = new JPasswordField();
        String userPass = "";
        Object[] message = {"Contraseña del usuario:  \n", pwd};
        int resp = JOptionPane.showConfirmDialog(null, message, "Retrieve Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (resp == JOptionPane.OK_OPTION) {
            //userPass = new String(StringMD.getStringMessageDigest(pwd.getText(), "SHA-256"));
            userPass=pwd.getText();
        }
        return userPass;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_edita;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jC_cursos;
    private javax.swing.JComboBox jC_dpto;
    private javax.swing.JComboBox jC_niveleducativo;
    private javax.swing.JComboBox jC_posicion;
    private javax.swing.JComboBox jC_tipo;
    private javax.swing.JCheckBox jCh_activa;
    private javax.swing.JFormattedTextField jF_fecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPasswordField jP_contra;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextArea jTA_NYP;
    private javax.swing.JTextArea jTA_PYE;
    private javax.swing.JTextArea jTA_RYR;
    private javax.swing.JTextArea jTA_principio;
    private javax.swing.JTextField jT_buscanomina;
    private javax.swing.JTextField jT_nombre;
    private javax.swing.JTextField jT_nunomina;
    private javax.swing.JTextField jT_uniclave;
    private javax.swing.JLabel lb_foto;
    // End of variables declaration//GEN-END:variables
}
